﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MusicConsole;
using Entities;
using Logic;

namespace MusicForms
{
    public partial class Form1 : Form
    {
        static Division division = DivisionFactory.CreateDivision();
        List<AbstractMusic> music = division.Music;

        public Form1()
        {
            InitializeComponent();

            foreach (AbstractMusic track in music)
            {
                listBox1.Items.Add("'" + track.Name + "' - " + track.Duration / 60 + ':' + track.Duration % 60);
            }
            UpdateLength();
        }

        public void UpdateLength()
        {
            int totalDuration = DivisionCalculator.CalculateDuration(division);
            string second = Convert.ToString(totalDuration % 60);
            if ((totalDuration % 60) < 10)
            {
                second = '0' + Convert.ToString(totalDuration % 60);
            }
            label1.Text = "Общая продолжительность всех треков: " + totalDuration / 60 + ':' + second;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this, division, music);
            form2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this, division, music, listBox1.SelectedIndex);
            form2.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            music.RemoveAt(listBox1.SelectedIndex);
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            listBox1.Refresh();
            UpdateLength();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
























/*foreach (AbstractMusic track in music)
{
    listBox1.Text = "Название трека: " + track.Name + "\n";
    listBox1.Text = "Продолжительность: " + track.Duration / 60 + ':' + track.Duration % 60 + "\n";
}*/